package util

import (
	"github.com/spf13/viper"
)

var Viper *viper.Viper

func init() {
	// Initialize the env configuration
	Viper = viper.GetViper()
	viper.SetConfigName("env")       // name of env config file (without extension)
	viper.SetConfigType("json")      // REQUIRED if the config file does not have the extension in the name
	viper.AddConfigPath("./config/") // optionally look for config in the working directory
	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err != nil {
		panic("failed to read env config file: " + err.Error())
	}

	// Initialize the all configuration which depends on the env
	env := Viper.GetString("env")
	Viper.SetConfigName(env)

	if err := viper.ReadInConfig(); err != nil {
		panic("failed to read config file which depends on the env: " + err.Error())
	}
}
